package Day22.reflect;

import java.lang.reflect.Field;

/**
 * @version 1.0
 * @BelongsProject:IntelliJ IDEA
 * @BelongsPackage:Day22.reflect
 * @Author:hyhWTX
 * @ClassName:ReflectDemo01
 * @CreateTime:2022年-10月-31日 14:14
 * @Description: 反射的使用1,获得对象成员变量
 */
public class ReflectDemo01 {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException, NoSuchFieldException {
        Class person = Person.class;
//        System.out.println(person);
        Field field = person.getDeclaredField("name");
        Object obj = person.newInstance();
        field.set(obj,"张三");
        //获得值
        Object value = field.get(obj);
        System.out.println(value);
    }
}
